package cn.hl.sfzy.controller;

import cn.hl.sfzy.entity.Article;
import cn.hl.sfzy.entity.Course;
import cn.hl.sfzy.service.ArticleService;
import cn.hl.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ArticleController
 * @Description TOOO
 * @Author Lilysi
 * @Date 2024//10//21//11:41
 * @Version 1.0
 */
@RestController
@RequestMapping("/Article")
@CrossOrigin
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    /**
     * @description:
     * @author: Lilysi
     * @date:
     * @param:
     * @return:
     **/
    @GetMapping("/find")
    public Result select(Article article) {
        List<Article> articles = articleService.getArticles(article);
        return Result.success(articles);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        int i = articleService.deleteArticle(id);
        return Result.success("删除成功");
    }
    @PostMapping
    public Result insert(@RequestBody Article article) {
        int i = articleService.addArticle(article);
        return Result.success(article);
    }
    @PutMapping
    public Result update(@RequestBody Article article) {
        int i = articleService.updateArticle(article);
        return Result.success(article);
    }
    @GetMapping("/pageSelect")
    public Result pageSelect(@RequestParam(required = false,defaultValue = "1") int pageNum, @RequestParam(required = false,defaultValue = "5") int pageSize, Article article) {
        PageInfo<Article> byPage = articleService.findByPage(pageNum, pageSize, article);
        return Result.success(byPage);
    }

    @GetMapping("/selectByConsultId")
    public Result selectByConsultId(@RequestParam(required = false,defaultValue = "1") int pageNum, @RequestParam(required = false,defaultValue = "3") int pageSize, Long teacher_id) {
        PageInfo<Article> byPage=articleService.selectByConsultId(pageNum, pageSize, teacher_id);
        return Result.success(byPage);
    }
    @GetMapping("/selectAll")
    public Result selectAll(@RequestParam(required = false,defaultValue = "1") int pageNum, @RequestParam(required = false,defaultValue = "3") int pageSize) {
        PageInfo<Article> byPage=articleService.selectAll(pageNum, pageSize);
        return Result.success(byPage);
    }
}
